/*
 * Copyright (c) 2017-present Ilhasoft.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package br.com.ilhasoft.support.validation.rule;


import ohos.agp.components.Component;
import ohos.agp.components.Text;

/**
 * 字符最大长度验证
 * Created by john-mac on 5/14/16.
 */
public class MaxLengthRule extends Rule<Text, Integer> {
    public MaxLengthRule(Text view,String content, Integer value, String errorMessage) {
        super(view, content,value, errorMessage);
    }

    @Override
    public boolean isValid(Text view) {
        return content.length() <= value;
    }

    @Override
    public void onValidationSucceeded(Text view) {
        view.setVisibility(Component.HIDE);
    }

    @Override
    public void onValidationFailed(Text view) {
        view.setVisibility(Component.VISIBLE);
        view.setText(errorMessage);
    }
}
